<?php

namespace App\Exports;

use App\Goods;
use Maatwebsite\Excel\Concerns\WithMultipleSheets;

class GoodsExport implements WithMultipleSheets
{

    protected $data;

    public function __construct($data)
    {
        $this->data = $data;
    }

    public function sheets(): array
    {
        $sheets = [];
        $sheets[] = $this->createData();
        return $sheets;
    }

    public function createData():array
    {
        $form = ['商品ID','商品名称','商品别名','分类','标准编码','编码','状态'];
        foreach ($this->data as $k => $v){
            $form[] = [$v->id,$v->name,$v->byname,$v->category_p->title.'|'.$v->category->title,$v->standard_code,$v->goods_code,$v->status];
        }
        return $form;
    }
}
